//
//  WPSearchCaseCell.m
//  wobingwoyi
//
//  Created by WGP on 2017/1/18.
//  Copyright © 2017年 WGP. All rights reserved.
//

#import "WPSearchCaseCell.h"

@interface WPSearchCaseCell ()

@property(nonatomic,strong)UILabel *searchResultLabel;
@property(nonatomic,strong)UIImageView *rightImageView;

@end
@implementation WPSearchCaseCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self searchResultLabel];
        [self rightImageView];
    }
    return self;
}

-(UILabel *)searchResultLabel
{
    if (_searchResultLabel == nil)
    {
        _searchResultLabel = [UILabel new];
        _searchResultLabel.text = @"";
        [self.myContentView addSubview:_searchResultLabel];
        
        [_searchResultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.eyeBtn.mas_bottom).offset(10);
            make.left.equalTo(self.eyeBtn);
            make.bottom.equalTo(self.myContentView).offset(-10);
        }];
    }
    return _searchResultLabel;
}

-(UIImageView *)rightImageView
{
    if (_rightImageView == nil)
    {
        _rightImageView =  [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_guard"]];
        [self.myContentView addSubview:_rightImageView];
        
        [_rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.equalTo(self.searchResultLabel);
            make.left.equalTo(self.searchResultLabel.mas_right).offset(10);
        }];
    }
    return _rightImageView;
}

-(void)setModel:(WPMRModel *)model
{
    [super setModel:model];
    
    NSString *str = model.searchCondition[0];
    
    if (str.length)
    {
        NSRange range = [str rangeOfString:self.searchStr];
        
        NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:GLobalFontColor};
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:str attributes:dict];
        [attStr addAttributes:@{NSForegroundColorAttributeName:RGB_COLOR(214, 76, 76)} range:range];
        self.searchResultLabel.attributedText = attStr;
    }
}

@end
